package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Geekvin
 * @CreateTime: 2022-10-15 21:47
 * @Version:v1.0.0
 * @Description:
 */
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    @ApiOperation("分页获取品牌列表")
    @GetMapping("{page}/{limit}")
    public Result index(@PathVariable Long page, @PathVariable Long limit) {
        Page<BaseTrademark> pageParam = new Page<>(page, limit);
        IPage<BaseTrademark> pageResult = baseTrademarkService.getPage(pageParam);
        return Result.ok(pageResult);
    }

    @ApiOperation("根据id获取品牌")
    @GetMapping("get/{id}")
    public Result getTrademarkById(@PathVariable Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    @ApiOperation("新增品牌")
    @PostMapping("save")
    public Result saveTrademark(@RequestBody BaseTrademark trademark){
        baseTrademarkService.save(trademark);
        return Result.ok();
    }

    @ApiOperation("更新品牌")
    @PutMapping("update")
    public Result updateTrademark(@RequestBody BaseTrademark trademark){
        baseTrademarkService.updateById(trademark);
        return Result.ok();
    }

    @ApiOperation("删除品牌")
    @DeleteMapping("remove/{id}")
    public Result removeTrademarkById(@PathVariable Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    @ApiOperation("查询全部品牌")
    @GetMapping("getTrademarkList")
    public Result<List<BaseTrademark>> getTrademarkList() {
        List<BaseTrademark> trademarkList = baseTrademarkService.list(null);
        return Result.ok(trademarkList);
    }




}
